//
//  WeiboCell.m
//  SinaWeibo
//
//  Created by Apple on 16/8/18.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "WeiboCell.h"
#import "WeiboFrameModel.h"
#import "StatuesModel.h"
#import "UserModel.h"

@interface WeiboCell()

@property (nonatomic, weak) UIImageView *userImageView;

@property  (nonatomic, weak) UILabel *nameLabel;

@property  (nonatomic, weak) UILabel *timeLabel;

@property (nonatomic, weak) UILabel *contentLabel;

@property (nonatomic, weak) UIImageView *pictureImageView;

@end

@implementation WeiboCell




-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        
        [self setupUI];
        
        
    }
    return self;
    
}

-(void)setupUI{
    
    // 1. 用户头像的imageView
    UIImageView *userImageView = [[UIImageView alloc] init];
    
    // 添加到 cell 的 contentView
    self.userImageView = userImageView;
    
    [self.contentView addSubview:userImageView];
    
    // 2. 用户名称的 UILabel
    UILabel *nameLabel = [[UILabel alloc] init];
    
    self.nameLabel = nameLabel;
    
    [self.contentView addSubview:nameLabel];
    
    // 3. 时间label
    UILabel *timeLabel = [[UILabel alloc]init];
    
    timeLabel.textColor = [UIColor grayColor];
    
    timeLabel.font = [UIFont systemFontOfSize:14];
    
    self.timeLabel = timeLabel;
    
    [self.contentView addSubview:timeLabel];
    
    // 4. 文本内容的 UILabel
    UILabel *contentLabel = [[UILabel alloc] init];
    
    self.contentLabel = contentLabel;
    
    // 自动换行
    contentLabel.numberOfLines = 0;
    
    // 设置字体为15
    //    contentLabel.font = [UIFont systemFontOfSize:15];
//    contentLabel.font = [UIFont systemFontOfSize:15];
    
    //
    
    [self.contentView addSubview:contentLabel];
    
    
    // 5. 配图的 UIImageView
    UIImageView *pictureImageView = [[UIImageView alloc] init];
    
    self.pictureImageView = pictureImageView;// 关联起来
    
    [self.contentView addSubview:pictureImageView];
    
    
}

-(void)setWeiboFrameModel:(WeiboFrameModel *)weiboFrameModel{
    
    _weiboFrameModel = weiboFrameModel;
    
    [self setupData];
    
    [self setupFrame];
    
}

-(void)setupData{
    
    StatuesModel *statues = _weiboFrameModel.StatuesModel;
    
    UserModel *user = statues.user;
    
    NSURL *userImgURL = [NSURL URLWithString:user.profile_image_url];
    
    [self.userImageView sd_setImageWithURL:userImgURL placeholderImage:[UIImage imageNamed:@"avatar_default_big"]];
    
    self.nameLabel.text = user.name;
    
    self.timeLabel.text = statues.created_at;
    
    self.contentLabel.text = statues.text;
    
    
    
}


-(void)setupFrame{
    
    self.userImageView.frame = _weiboFrameModel.userImageFrame;
    
    self.nameLabel.frame = _weiboFrameModel.userNmaeFrame;
    
    self.timeLabel.frame = _weiboFrameModel.timeFrame;
    
    self.contentLabel.frame = _weiboFrameModel.contentFrame;
    
}


@end
